<?php
$this->Paginator->options(array(
    'update' => '#content-outer',
    'evalScripts' => false,
    'before' => $this->Js->get('#busy-indicator')->effect('fadeIn', array('buffer' => false)),
    'complete' => $this->Js->get('#busy-indicator')->effect('fadeOut', array('buffer' => false)),
));

if(isset($this->request->data) && !empty($this->request->data)){
    $this->Paginator->options(array('url' => $this->request->data['Ticket']));
}
$pageOption = $this->Paginator->params();
?>
  <?php  
         $DAY = Setting::get_option('DAY');
         $HOUR = Setting::get_option('HOUR');
         $MINUTE = Setting::get_option('MINUTE');
         $SECOND = Setting::get_option('SECOND');
  ?>
<?php echo $this->Html->image('loading.jpg', array('id' => 'busy-indicator', 'style' => 'display:none;')); ?>
<div id="content">
	<!--  start page-heading -->
	<div id="page-heading">
		<h1>General Enquiry Tickets</h1>
    <?php //echo $this->Html->link("Ticket", array('action' => 'add')); ?>&nbsp;&nbsp;
	</div>
	<!-- end page-heading -->
	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
	<tr>
		<th rowspan="3" class="sized">
        <?php echo $this->Html->image('/images/shared/side_shadowleft.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
    </th>
		<th class="topleft"></th>
		<td id="tbl-border-top">&nbsp;</td>
		<th class="topright"></th>
		<th rowspan="3" class="sized">
        <?php echo $this->Html->image('/images/shared/side_shadowright.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
    </th>
	</tr>
	<tr>
		<td id="tbl-border-left"></td>
		<td>
		<!--  start content-table-inner ...................................................................... START -->
		
			<!--  start table-content  -->

		<div id="content-table-inner">

				<table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
				<tr>
					<th class="table-header-repeat line-left minwidth-1">
               <?php echo $this->Paginator->sort('key', 'Ticket ID'); ?>
          </th>
					<th class="table-header-repeat line-left minwidth-1">
               <?php echo $this->Paginator->sort('subject', 'Subject'); ?>
          </th>
					<th class="table-header-repeat line-left minwidth-1">
               <?php echo $this->Paginator->sort('email', 'Email'); ?>
          </th>
					<th class="table-header-repeat line-left minwidth-1">
               <?php echo __('SLA'); ?>
          </th>
                                        <th class="table-header-repeat line-left minwidth-1">
               <?php echo __('Status'); ?>
          </th>
          				<th class="table-header-repeat line-left">
               <?php echo $this->Paginator->sort('created', 'Created'); ?>
          </th>
					<th class="table-header-repeat line-left">
               Action
          </th>          
				</tr>

<?php foreach ($tickets as $ticket): ?>
    <?php $class = $ticket['Ticket']['viewed'] == 0? 'unread':'read'; ?>
    <tr class="<?php echo $class; ?>">
        <td><?php echo $this->Html->link('#'.$ticket['Ticket']['key'], array('action' => 'view', $ticket['Ticket']['id'], 'admin' => true)); ?></td>
        <td>
            <?php echo $ticket['Ticket']['subject']; ?>
        </td>
        <td>
            <?php echo $ticket['Ticket']['email']; ?>
        </td>
        <td>
            <?php echo $this->Slashow->makeSla($ticket, $DAY, $HOUR, $MINUTE, $SECOND); ?>
        </td>
        <td><?php echo $ticket['Ticket']['status']; ?></td>
        <td>
            <?php echo $ticket['Ticket']['created']; ?>
        </td>
        <td>
            <?php echo $this->Html->link('View', array('action' => 'view', $ticket['Ticket']['id'], 'admin' => true), array('class' => 'action')); ?>
            <?php echo $this->Html->link('Change Status', array('controller' => 'tickets', 'action' => 'change_status', $ticket['Ticket']['id']), array('class' => 'change_status')); ?>
        </td>
    </tr>
<?php endforeach; ?>

</table>
			<div class="clear"></div>
		<!--  start paging..................................................... -->
  <? if($pageOption['pageCount'] > 1): ?>	
    <table border="0" cellpadding="0" cellspacing="0" id="paging-table">
        <?php echo $this->element('pagination');?>       
		</table> 
		<!--  end paging................ -->
  <? endif; ?>	

		</div>
	 
			  <?php //echo $this->element("Tickets".'/listing'); ?>
      <!--  end content-table  -->
		<!--  end content-table-inner ............................................END  -->
		</td>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</table>
	<div class="clear">&nbsp;</div>

</div>
<?php
    echo $this->Js->writeBuffer();
?>	
<style>
#paging-table a {
  padding: 0 12px 12px;
}
</style>
<script type="text/javascript">
  jQuery(document).ready(function() {
    jQuery("#ticketMenu").addClass("current");
  });
</script>